package ${model.packageName}.${model.modulePackage}.action;

import javax.validation.Valid;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.Map; 
import javax.servlet.http.HttpServletRequest;
import com.okrsoa.commons.base.BaseAction;
import com.okrsoa.commons.model.FormParam;
import com.okrsoa.commons.model.Member;
import com.okrsoa.commons.model.PageParam;
import com.okrsoa.commons.util.DateUtil;
import com.okrsoa.commons.util.ServletUtil; 
import com.okrsoa.commons.util.HandleMessyCode; 
import ${model.packageName}.${model.modulePackage}.bean.${model.model};
import ${model.packageName}.${model.modulePackage}.service.I${model.model}Service;

/**
*@Title: ${model.model}Controller
*@Description: ${model.comment} 的action控制层
*@author ${model.author}
*/
@Controller
@RequestMapping("${model.modelL}")
public class ${model.model}Action extends BaseAction {
	@Autowired
	private I${model.model}Service  i${model.modelL}Service;
	/**
	 * 跳转到 ${model.comment}页面
	 * @return
	 */
	@RequiresPermissions("${model.modelL}:read")
	@RequestMapping("load")
	public String load(){
		return "${model.modulePackage}/${model.modelL}/load";
	}
	/**
	 * 查询 ${model.comment}
	 * 如果params中出现乱码，可使用HandleMessyCode.handle(ServletsUtil.getParameters(request))
	 * @param param
	 * @param lv
	 * @return
	 */ 
	@RequiresPermissions("${model.modelL}:read")
	@RequestMapping("query")
	public ModelAndView query(HttpServletRequest request,PageParam param, ${model.model} ${model.modelL}){
		Map<String, Object> params = HandleMessyCode.handle(ServletUtil.getParameters(request));
		return ajaxJsonEscape(i${model.modelL}Service.selectQuery(params,${model.modelL},param));
	}
	/**
	 * 跳转到 ${model.comment}增加页面
	 * @return
	 */
	@RequiresPermissions("${model.modelL}:add")
	@RequestMapping("addPage")
	public String addPage(){
		return "${model.modulePackage}/${model.modelL}/add";
	}
	/**
	 * 增加 ${model.comment}
	 * @param ${model.modelL}
	 * @return
	 */
	@RequiresPermissions("${model.modelL}:add")
	@RequestMapping("add")
	public ModelAndView add(@Valid ${model.model} ${model.modelL}, Errors errors){
		if(errors.hasErrors()) {  
			ModelAndView mav=getValidationMessage(errors);
			if(mav!=null)return mav;
        }
		 
		return ajaxDone(i${model.modelL}Service.save(${model.modelL}));
	}
	/**
	 * 跳转到 ${model.comment}修改页面
	 * @param id
	 * @return
	 */
	@RequiresPermissions("${model.modelL}:update")
	@RequestMapping("updatePage")
	public String  updatePage(String id,ModelMap map){
		${model.model} obj=i${model.modelL}Service.get(${model.model}.class, id);
		if(obj==null){
			
			return NODATA;
		}
		 map.addAttribute("${model.modelL}",obj);
		 return "${model.modulePackage}/${model.modelL}/add";
	}
	/**
	 * 修改 ${model.comment}
	 * @param ${model.modelL}
	 * @return
	 */
	@RequiresPermissions("${model.modelL}:update")
	@RequestMapping("update")
	public ModelAndView update(${model.model} ${model.modelL}){
		 
		return ajaxDone(i${model.modelL}Service.update(${model.modelL}));
	}
	
	/**
	 * 保存包含修改，添加 ${model.comment}
	 * @param ${model.modelL}
	 * @return
	 */
	@RequiresPermissions("${model.modelL}:update")
	@RequestMapping("save")
	public ModelAndView save(${model.model} ${model.modelL}){
		 
		return ajaxDone(i${model.modelL}Service.saveOrUpdate(${model.modelL}));
	}
	/**
	 * 批量删除  ${model.comment}
	 * @param ids
	 * @return
	 */
	@RequiresPermissions("${model.modelL}:delete")
	@RequestMapping("delete")
	public ModelAndView delete(String[] ids){
		return ajaxDone(i${model.modelL}Service.delete(ids));
	}
	/**
	 * 跳到查看 ${model.comment}内容页面
	 * @param id
	 * @return
	 */
	@RequestMapping("show")
	public String show(String id,ModelMap map){
		${model.model} rl=i${model.modelL}Service.get(${model.model}.class, id);
		if(rl==null){
			return NODATA;
		}
		map.addAttribute("${model.modelL}", rl);
		return "${model.modulePackage}/${model.modelL}/show";
	}
	 
}
